package com.example.a2205douyin.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a2205douyin.R;
import com.example.a2205douyin.adapter.VideoAdapter;
import com.example.a2205douyin.baseMVVM.view.BaseViewFragment;
import com.example.a2205douyin.databinding.FragmentShoucangBinding;
import com.example.a2205douyin.db.AppDBUtils;
import com.example.a2205douyin.entity.VideoEntity;

import java.util.ArrayList;
import java.util.List;


public class ShoucangFragment extends BaseViewFragment<FragmentShoucangBinding> {
    List<VideoEntity.DataBean> videos = new ArrayList<>();
    VideoAdapter videoAdapter;
    public ShoucangFragment() {
        // Required empty public constructor
    }


    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        videoAdapter = new VideoAdapter(R.layout.item_video,videos);
        binding.rv.setAdapter(videoAdapter);
        binding.rv.setLayoutManager(new GridLayoutManager(getContext(),3));

        //请求数据库数据
        List<VideoEntity.DataBean> beans = AppDBUtils.getInstance().getVideoDao().queryAll();
        videos.clear();//先清空，在添加
        videos.addAll(beans);
        videoAdapter.notifyDataSetChanged();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_shoucang;
    }

    @Override
    public void onResume() {
        super.onResume();
        //请求数据库数据
        List<VideoEntity.DataBean> beans = AppDBUtils.getInstance().getVideoDao().queryAll();
        videos.clear();//先清空，在添加
        videos.addAll(beans);
        videoAdapter.notifyDataSetChanged();
    }
}